#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <unordered_set>
#include <algorithm>

int main()
{
    std::string istr;
    std::string dict_str;
    std::cin >> istr;
    std::cin >> dict_str;

    std::istringstream iss(dict_str);
    std::string s;
    std::unordered_set<std::string> dic_set;

    int max_len = 0;
    while (std::getline(iss, s, ','))
    {
        dic_set.insert(s);
        max_len = std::max(max_len, (int)s.size());
    }

    int l = 0, r = 0;
    std::vector<std::string> split_str;
    while (r < istr.size())
    {
        if (istr[r] > 'z' || istr[r] < 'a')
        {
            r++;
            l = r;
            continue;
        }
        std::string ts;
        ts.push_back(istr[r]);
        int p = r;
        while (r - l + 1 <= max_len && r < istr.size())
        {
            r++;
            ts.push_back(istr[r]);
            if (dic_set.count(ts) > 0)
            {
                p = r;
            }
        }
        ts.resize(p - l + 1);
        split_str.push_back(ts);
        dic_set.erase(ts);
        l = p + 1;
        r = l;
    }

    for (int i = 0; i < split_str.size() - 1; i++)
    {
        std::cout << split_str[i] << ",";
    }
    std::cout << split_str.back() << std::endl;

    return 0;
}